package cn.new7as.cas5s.tool.util;

import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferenceUtils {
    private static final String PREF_NAME = "easyPreferences";
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    public SharePreferenceUtils(Context context) {
        sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }


    public void putString(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }


    public String getString(String key, String defaultValue) {
        return sharedPreferences.getString(key, defaultValue);
    }

    //
    public void putInt(String key, int value) {
        editor.putInt(key, value);
        editor.apply();
    }

    //
    public int getInt(String key, int defaultValue) {
        return sharedPreferences.getInt(key, defaultValue);
    }

    //
    public void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }

    //
    public boolean getBoolean(String key, boolean defaultValue) {
        return sharedPreferences.getBoolean(key, defaultValue);
    }

    //
    public void clear() {
        editor.clear();
        editor.apply();
    }

    public void clearlogin() {
        editor.putString("useruniquecode","");
        editor.apply();
    }
}

